package service;

import dao.*;
import entity.*;

import util.*;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;

public class SchoolService implements SchoolServiceInterface{
    private SchoolService(){};
    static SchoolService schoolService;
    public static SchoolService getInstance(){
        if(schoolService==null){
            schoolService=new SchoolService();
        }
        return schoolService;
    }
    private SchoolDaoImpl schoolDao=SchoolDaoImpl.getInstance();

    @Override
    public School find(Long id) throws SQLException {
        Connection connection= JdbcHelper.getConn();
        return schoolDao.find(id,connection);
    }

    @Override
    public Collection<School> findAll() throws SQLException{
        Connection connection=JdbcHelper.getConn();
        return schoolDao.findAll(connection);

    }

    @Override
    public Collection<School> findAll(Pagination pagination) throws SQLException {
        Connection connection=JdbcHelper.getConn();
        return schoolDao.findAll(connection,pagination);
    }

    @Override
    public boolean add(School school) throws SQLException {
        Connection connection=JdbcHelper.getConn();
        boolean added=schoolDao.add(connection,school);
        JdbcHelper.close(connection);
        return added;
    }


}
